#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<string>
#include<queue>

using namespace std;

typedef pair<int, int> PII;

bool isOneBitCharacter(vector<int>& bits) {
    int n = bits.size(), i = 0;
    while (i < n - 1)
        i += bits[i] + 1;
    return i == n - 1;
}

bool isFlipedString(string s1, string s2) {
    return s1.size() == s2.size() && (s1 + s1).find(s2) != string::npos;
}

int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
int findMaxFish(vector<vector<int>>& grid) {
    int n = grid.size(), m = grid[0].size();
    vector<vector<bool>> st(n, vector<bool>(m, false));
    int res = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            if (grid[i][j] == 0) continue;
            if (st[i][j] == true)    continue;
            queue<PII> q;
            int cnt = 0;
            q.push({ i,j });
            st[i][j] = true;
            while (!q.empty())
            {
                int a = q.front().first, b = q.front().second;
                cnt += grid[a][b];
                q.pop();
                for (int i = 0; i < 4; i++)
                {
                    int x = a + dx[i];
                    int y = b + dy[i];
                    if (x >= 0 && x < n && y >= 0 && y < m)
                        if (!st[x][y] && grid[x][y] != 0)
                        {
                            q.push({ x,y });
                            st[x][y] = true;
                        }
                }
            }
            res = max(res, cnt);
        }
    return res;
}

int main()
{
    vector<vector<int>> vv = { {6,1,10 } };
    cout << findMaxFish(vv);
    return 0;
}